package com.foreverwin.jzymes.report.task.controller;

import com.foreverwin.jzymes.common.domain.NcData;
import com.foreverwin.jzymes.common.util.CommonMethods;
import com.foreverwin.jzymes.framework.base.AjaxResult;
import com.foreverwin.jzymes.framework.base.BaseController;
import com.foreverwin.jzymes.framework.exception.BusinessException;
import com.foreverwin.jzymes.framework.util.DateUtil;
import com.foreverwin.jzymes.qc.check.domain.QcCheck;
import com.foreverwin.jzymes.qc.check.domain.QcCheckFaiFail;
import com.foreverwin.jzymes.report.task.service.ITaskReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/report/task")
public class TaskReportController extends BaseController {
    @Autowired
    ITaskReportService taskReportService;

    /**
     *  三次元、目检报表
     *
     * @param jsonMap
     * @return
     */
    @RequestMapping("/taskReport")
    public AjaxResult taskReport(@RequestParam Map<String,Object> jsonMap ){
        jsonMap.put("site", CommonMethods.getSite());
        try{

           List<QcCheck> qcChecks = taskReportService.findQcCheckByReport( jsonMap );

            return AjaxResult.returnSuccess().put("value",qcChecks);
        }catch ( BusinessException e){
            return AjaxResult.returnError( e.getMessage() );
        }

    }

    /**
     *  三次元、目检不良项目
     *
     * @param jsonMap
     * @return
     */
    @RequestMapping("/taskNcData")
    public AjaxResult taskNcData(@RequestParam Map<String,Object> jsonMap){

        try{
            List<NcData> ncData = taskReportService.findtaskNcData( jsonMap );

            return AjaxResult.returnSuccess().put("value",ncData);
        }catch ( BusinessException e){
            return AjaxResult.returnError( e.getMessage() );
        }

    }

    /**
     *  三次元测量值
     *
     * @param createdDateTime
     * @return
     */
    @RequestMapping("/taskFail")
    public AjaxResult taskFail(@RequestParam String createdDateTime ){

        try{

           List<QcCheckFaiFail> qcCheckFaiFails = taskReportService.findtaskFail( DateUtil.parse(createdDateTime) );

            return AjaxResult.returnSuccess().put("value",qcCheckFaiFails);
        }catch ( BusinessException e){
            return AjaxResult.returnError( e.getMessage() );
        }

    }
}
